package com.show.web.unit;

import com.show.dto.Tree;
import com.show.dto.unit.Unit;
import com.show.service.unit.UnitService;
import com.show.service.unit.UnitTypeService;
import com.show.util.FileUtil;
import com.show.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

/**
 * 部件展示跳转控制器
 *
 * @author liukai
 */
@Controller
public class UnitShowTurnController {

    private UnitTypeService unitTypeService;

    private UnitService unitService;

    private FileUtil fileUtil;

    @Autowired
    public UnitShowTurnController(UnitTypeService unitTypeService, UnitService unitService, FileUtil fileUtil) {
        this.unitTypeService = unitTypeService;
        this.unitService = unitService;
        this.fileUtil = fileUtil;
    }

    /**
     * 跳转到部件展示index页面
     *
     * @author liukai
     */
    @GetMapping(value = "toUnit")
    public String toUnit() {
        return "unit_manage/unit_index";
    }

    /**
     * 跳转到部件展示list页面
     *
     * @author liukai
     */
    @GetMapping(value = "toUnitList")
    public String toUnitList(Map<String, Object> map) {
        List<Tree> list = unitTypeService.getUnitTypeTree();
        map.put("UnitTypeList", list);
        map.put("SERVERIP", fileUtil.getSERVERIP());
        map.put("LNG", fileUtil.getLNG());
        map.put("LAT", fileUtil.getLAT());
        return "unit_manage/unit_list";
    }

    /**
     * 根绝id数组查询部件信息
     *
     * @param unitTypeIds 部件类型id
     * @author liukai
     */
    @PostMapping(value = "getUnitByTypeId")
    public String getUnitByTypeId(Map<String, Object> map, @RequestParam(value = "ids[]") String[] unitTypeIds, Integer page, Integer pageSize) {
        PageUtil<Unit> list = unitService.getUnitByTypeId(unitTypeIds, page, pageSize);
        map.put("datas", list);
        return "unit_manage/showUnitPage";
    }


}
